
// Needs to works on several platforms.
//#include <platforms/Setup.h>
#include <platforms/Xna/Setup.h>

#include <System/Diagnostics/Debug.h>
#include <System/Threading/Thread.h>
#include <System/Threading/ThreadStart.h>
#include <System/IO/FileStream.h>
#include <System/Text/Encoding.h>
#include <System/GC.h>

#include "MainClass.h"

#include <std/variant_map.h>

using namespace Riccsson::System;
using namespace Riccsson::System::IO;
using namespace Riccsson::System::Text;
using namespace Riccsson::System::Threading;

namespace RiccssonXnaText
{
	class Program
	{
		public: static Void MemoryReport()
		{
			while (true)
			{
				Thread::Sleep(1000);

				GC_PTR<string> report = GC::ReportMemory();

				FileStream file(STR("C:/Riccsson.System.MemoryReport.txt"), FileMode::Create);

				GC_PTR<Array<byte>> bytes = Text::Encoding::UTF8->GetBytes(report);
				file.Write(bytes, 0, report->Length);
				file.Close();
			}

			return Void();
		}

		public: static void Main(Array<GC_PTR<String>>* args)
		{
			// Memory reporting thread.
			Thread thread(&Program::MemoryReport);
			//thread.Start();

			using (GC_PTR<RiccssonXnaText::MaincClass>, game, GC_PTR<RiccssonXnaText::MaincClass>( new RiccssonXnaText::MaincClass() ))
			{
				Riccsson::System::Diagnostics::Debug::WriteLine("game->Run();");;
				game->Run();
			}
		}
	};
}

StartupObject(RiccssonXnaText::Program, xnatest, xnatest);